package cn.iocoder.yudao.module.trade.service.deliverypickupstoreimage;

import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.transaction.annotation.Transactional;

import java.util.*;
import cn.iocoder.yudao.module.trade.controller.admin.deliverypickupstoreimage.vo.*;
import cn.iocoder.yudao.module.trade.dal.dataobject.deliverypickupstoreimage.DeliveryPickUpStoreImageDO;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.pojo.PageParam;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;

import cn.iocoder.yudao.module.trade.dal.mysql.deliverypickupstoreimage.DeliveryPickUpStoreImageMapper;

import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
import static cn.iocoder.yudao.module.trade.enums.ErrorCodeConstants.*;

/**
 * 门店证件图片 Service 实现类
 *
 * @author 芋道源码
 */
@Service
@Validated
public class DeliveryPickUpStoreImageServiceImpl implements DeliveryPickUpStoreImageService {

    @Resource
    private DeliveryPickUpStoreImageMapper deliveryPickUpStoreImageMapper;

    @Override
    public Integer createDeliveryPickUpStoreImage(DeliveryPickUpStoreImageSaveReqVO createReqVO) {
        // 插入
        DeliveryPickUpStoreImageDO deliveryPickUpStoreImage = BeanUtils.toBean(createReqVO, DeliveryPickUpStoreImageDO.class);
        deliveryPickUpStoreImageMapper.insert(deliveryPickUpStoreImage);
        // 返回
        return deliveryPickUpStoreImage.getId();
    }

    @Override
    public void updateDeliveryPickUpStoreImage(DeliveryPickUpStoreImageSaveReqVO updateReqVO) {
        // 校验存在
        validateDeliveryPickUpStoreImageExists(updateReqVO.getId());
        // 更新
        DeliveryPickUpStoreImageDO updateObj = BeanUtils.toBean(updateReqVO, DeliveryPickUpStoreImageDO.class);
        deliveryPickUpStoreImageMapper.updateById(updateObj);
    }

    @Override
    public void deleteDeliveryPickUpStoreImage(Integer id) {
        // 校验存在
        validateDeliveryPickUpStoreImageExists(id);
        // 删除
        deliveryPickUpStoreImageMapper.deleteById(id);
    }

    private void validateDeliveryPickUpStoreImageExists(Integer id) {
        if (deliveryPickUpStoreImageMapper.selectById(id) == null) {
            throw exception(DELIVERY_PICK_UP_STORE_IMAGE_NOT_EXISTS);
        }
    }

    @Override
    public DeliveryPickUpStoreImageDO getDeliveryPickUpStoreImage(Integer id) {
        return deliveryPickUpStoreImageMapper.selectById(id);
    }

    @Override
    public PageResult<DeliveryPickUpStoreImageDO> getDeliveryPickUpStoreImagePage(DeliveryPickUpStoreImagePageReqVO pageReqVO) {
        return deliveryPickUpStoreImageMapper.selectPage(pageReqVO);
    }

}